home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 8_3.lha / 8_3 / 8_3_mail.c < prev    next >
Text File  |  1993-08-08  |  875b  |  43 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. / Exercise 8.3
  6. / Read in a mail and address, with error checking
  7. include <stream.h>
  8. include <nameaddress.h>
  9.  
  10. nt read_name_and_address(ostream &out, istream &in,
  11.    name_and_address *val)
  12.  
  13.    // set up flushing of the output stream
  14.    ostream *old = in.tie(&out);
  15.  
  16.    // loop until we get something right
  17.    for ( ; ;
  18.  out << "Try again " <<
  19.      "(must be longer than one line)\n")
  20. {
  21. out << "Type a mail address, " <<
  22.     "followed by a blank line: ";
  23.  
  24. // read a line, including the newline
  25. name_and_address ret;
  26. in >> ret;
  27.  
  28. // check the value
  29. if (!in)
  30.     {
  31.     in.tie(old);
  32.     return 0;
  33.     }
  34. if (!ret.name[0] || !ret.name[1])
  35.     continue;
  36.  
  37. // return the value, restoring the old tie first
  38. in.tie(old);
  39. *val = ret;
  40. return 1;
  41. }
  42.  
  43.